package com.xcity.pomelo.response;

import com.xcity.db.entity.Player;
import com.xcity.game.combat.attr.CombatAttribute;
import com.xcity.game.common.PlayerPool;
import com.xcity.game.player.PlayerTrainService;
import com.xcity.game.player.template.DestinyTemplate;

import naga.x.util.CommonUtils;
import naga.x.util.NumberUtils;

public abstract class AbstractDestinyResponse extends Response {
	
	public int starsNum; // 副本星数
	public int destinyLvl; // 天命等级
	public int starLvl; // 星级
	public int destinyMaxLvl; // 天命最高等级
	public Required required; // 升级需求等信息
	
	public static class Required {
		public short[] attrsIndex = NumberUtils.EMPTY_SHORTS; // 升级后成长数值
		public Object[] attrs = CommonUtils.EMPTY_OBJECT_ARRAY;
		public int levelLimit;
		public int costStarsNum; // 升级消耗副本星数
		public int costGold; // 升级消耗现金
		public Required(DestinyTemplate template) {
			CombatAttribute[] refers = template.getAttributes();
			this.attrsIndex = new short[refers.length];
			this.attrs = new Object[refers.length];
			for (int i = 0; i < refers.length; i++) {
				CombatAttribute refer = refers[i];
				this.attrsIndex[i] = (short) refer.getType().ordinal();
				this.attrs[i] = refer.format(refer.getValue());
			}
			this.costStarsNum = template.getCostStars();
			this.costGold = template.getGold();
		}
	}

	public AbstractDestinyResponse(int serial, Player player, PlayerTrainService service) {
		super(serial);
		this.starsNum = player.getPool().getIntValue(PlayerPool.PROPERTY_STAGE_STARS);
		this.destinyLvl = player.getDestinyLvl();
		DestinyTemplate template = service.getDestinyTemplate(player.getDestinyLvl());
		if (template != null) {
			this.starLvl = template.getStarLvl();
		}
		this.destinyMaxLvl = service.getMaxDestinyLevel();
		DestinyTemplate next = service.getDestinyTemplate(player.getDestinyLvl() + 1);
		if (next != null) {
			this.required = new Required(next);
		}
	}

}
